/**
 * 微信 scrapy schema
 */

var Schema = require('mongoose').Schema,
    ObjectId = require('mongoose').Types.ObjectId,
    wechatSchema;

wechatSchema = new Schema({
    post_time:Date,
    author:String,
    like_num:Number,
    read_num:Number,
    title:String,
    trim_content:String,
    keywords:Array,
    sentiment:Number
});

//statics
wechatSchema.statics = {
    findByKeyword : function(keyword,callback){
        var re = new RegExp(keyword);
        return this
            .find({$or:[{'title': re},{'trim_content.content':re}]}, {
            post_time:1,
            author:1,
            like_num:1,
            read_num:1,
            title:1,
            trim_content:1,
            keywords:1,
            sentiment:1
        }, callback);
    }
};

exports.wechatSchema = wechatSchema;